package com.ohuang.launcher;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class WebActivity extends Activity {


    public static void start(Context context, String url) {
        Intent starter = new Intent(context, WebActivity.class);
        starter.putExtra("url", url);
        context.startActivity(starter);
    }


    public static void start(Context context, String url, String title) {
        Intent starter = new Intent(context, WebActivity.class);
        starter.putExtra("url", url);
        starter.putExtra("title", title);
        context.startActivity(starter);
    }

    private String url;
    private String title;
    private WebView webView;

    @Override
    protected void onCreate( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         webView=new WebView(this);
        setContentView(webView);
        setTheme(android.R.style.Theme_Material);
        url = getIntent().getStringExtra("url");
        title = getIntent().getStringExtra("title");

        initWebView();
        if (!TextUtils.isEmpty(title)){
           setTitle(title);
        }else {
          setTitle("");
        }
        if (!TextUtils.isEmpty(url)){
            webView.loadUrl(url);
        }

    }


    private void initWebView(){
        if (webView!=null){
            webView.getSettings().setJavaScriptEnabled(true);
            webView.getSettings().setPluginState(WebSettings.PluginState.ON);
            webView.requestFocus();
            webView.getSettings().setSupportZoom(true);
            webView.getSettings().setTextZoom(100);
            webView.getSettings().setUseWideViewPort(true);
            webView.getSettings().setLoadWithOverviewMode(true);
            webView.getSettings().setDomStorageEnabled(true);
            webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        }

    }
}
